<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"   pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>IPL 5 - Registration Details</title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta http-equiv="content-language" content="" />
    <link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%@ include file="global.jsp" %>
<%
String userName = (String) session.getAttribute("userName");
String league = (String) session.getAttribute("league");
if(null != userName){
String resposeText = "";
String errorMesg = (String) session.getAttribute("error");
out.println("<script>alert(\\"+errorMesg+"\\)</script>");
if (session.getAttribute("resposeText") != null) {

	if(null != (String)session.getAttribute("resposeText")){ 
		out.println("<script>alert("+(String)session.getAttribute("resposeText")+")</script>");
    }else{
    	out.println("<script>alert(\"No Mesg\")</script>");
    }
	
	if(("Succesfully Submited").equals((String)session.getAttribute("resposeText"))){ 
		out.println("<script>alert(\"Succesfully Submited\")</script>");
    }else if(("User Not Registered").equals((String)session.getAttribute("resposeText"))){
    	out.println("<script>alert(\"User Not Registered\")</script>");
    }else if(("Entry already made").equals((String)session.getAttribute("resposeText"))){
    	out.println("<script>alert(\"Entry already made\")</script>");
    }else if(("Please enter your name").equals((String)session.getAttribute("resposeText"))){
    	out.println("<script>alert(\"Please enter your name\")</script>");
    }else if(("Exception Occurred").equals((String)session.getAttribute("resposeText"))){
    	out.println("<script>alert(\"Exception Occurred\")</script>");
    }else if(("Unauthorized User").equals((String)session.getAttribute("resposeText"))){
    	out.println("<script>alert(\"Unauthorized User\")</script>");
    }else if(("UserName Not Entered").equals((String)session.getAttribute("resposeText"))){
    	out.println("<script>alert(\"UserName Not Entered\")</script>");
    }else{
    	out.println("<script>alert(\\"+errorMesg+"\\)</script>");
    } 
} 
%>


    <div id="page">
        <div id="header">
            <h1><a href="#">IPL-5  2012</a></h1>
        </div>
        <%@ include file="links.jsp" %>
        <div>
			<%
			if(null!=errorMesg){
				%>
				<div style="color:red;">
				<b><%=errorMesg%></b>
				</div>
				<%
			}
			%>
		</div>
		<div>
			<table width="100%">
				<tr>
					<td align="right">
						Logged User: <%=userName%> &nbsp; League: <%=league%> &nbsp; <a href="logout.jsp">logout</a>
					</td>
				</tr>
			</table>
			
		</div>
         
        <div id="main">		              
            <div id="content">
            
            
            <form  action="/IPL5/processResults.jsp"  name="result" method = "post">
			<table  id="main_schedule" width="100%" style="tableClass" border="1" cellspacing="1" cellpadding="1">
			<tbody>
			<tr>
			<th><font COLOR="#33FFFF"><strong>S.No</strong></th>
			<th><font COLOR="#33FFFF"><strong>Day - Date</strong></th>
			<th><font COLOR="#33FFFF"><strong>MatchTime</strong></th>
			<th><font COLOR="#33FFFF"><strong>Playing Teams</strong></th>
			<th><font COLOR="#33FFFF"><strong>Venue</strong></th>
			<th><font COLOR="#33FFFF"><strong>Winner</strong></th>
			<th><font COLOR="#33FFFF"><strong>MOM</strong></th>
			<th><font COLOR="#33FFFF"><strong>Select</strong></th>
			<th><font COLOR="#33FFFF"><strong>Go</strong></th>
			</tr>
			
			
			<%
					
			try{
				Class.forName(db_driver);
				Connection conn = DriverManager.getConnection(db_url, db_user, db_password);
		        Statement stmt = conn.createStatement();
				ResultSet rset = stmt.executeQuery("select id, day, date, time, matchid, cutoff, team1, team2, winner, mom, venue from fixtures");
				String parameter = null;
		        while (rset.next()){
				parameter = rset.getString(5)+"*"+rset.getDate(3)+" "+rset.getString("cutoff");
		        	DateFormat todayFormat = new SimpleDateFormat("yyyy-MM-dd");	        	
		        	DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		        	todayFormat.setTimeZone(TimeZone.getTimeZone("IST"));
		        	dateFormat.setTimeZone(TimeZone.getTimeZone("IST"));
		        	java.util.Date currentDate = Calendar.getInstance().getTime();
		        	String now = todayFormat.format(currentDate);
		        	java.util.Date voteTime = todayFormat.parse(rset.getString("date"));
		        	java.util.Date today = todayFormat.parse(now);
		        	//System.out.println(today.toString());
		        	//System.out.println(voteTime.toString());
		        	if(voteTime.before(today)){
		        		%>
			        	<tr>
			        	<td><b><font COLOR="#FFFF00"><center><%=rset.getInt(1)%></font></center></b></td>
			        	<td><b><font COLOR="#FFFF00"><center><%=rset.getString(2)%> - <%=rset.getDate(3)%></font></center></b></td>
			        	<td><b><font COLOR="#FFFF00"><center><%=rset.getString("time")%></font></center></b></td>
			        	<td><b><font COLOR="#FFFF00"><center><%=rset.getString(7)%> vs <%=rset.getString(8)%></font></center></b></td>
			        	<td><b><font COLOR="#FFFF00"><center><%=rset.getString(11)%></font></center></b></td>
			        	<td><b><font COLOR="#FFFF00"><center><%=rset.getString(9)%></font></center></b></td>
			        	<td><b><font COLOR="#FFFF00"><center><%=rset.getString(10)%></font></center></b></td>
			        	<td><b><font COLOR="#FFFF00"><center><input type="radio" name="matchId" value="<%=parameter%>"></font></b></td>
			        	<td><input type="image" height="20" width="20" src="images/blackPlay.png"/></font></b></td>
			        	</tr>
			        	<%
		        	}else if(voteTime.equals(today)){
		        		%>
			        	<tr>
			        	<td><b><font COLOR="#66FF00"><center><%=rset.getInt(1)%></font></center></b></td>
			        	<td><b><font COLOR="#66FF00"><center><%=rset.getString(2)%> - <%=rset.getDate(3)%></font></center></b></td>
			        	<td><b><font COLOR="#66FF00"><center><%=rset.getString("time")%></font></center></b></td>
			        	<td><b><font COLOR="#66FF00"><center><%=rset.getString(7)%> vs <%=rset.getString(8)%></font></center></b></td>
			        	<td><b><font COLOR="#66FF00"><center><%=rset.getString(11)%></font></center></b></td>
			        	<td><b><font COLOR="#66FF00"><center><%=rset.getString(9)%></font></center></b></td>
			        	<td><b><font COLOR="#66FF00"><center><%=rset.getString(10)%></font></center></b></td>
			        	<td><b><font COLOR="#66FF00"><center><input type="radio" name="matchId" value="<%=parameter%>"></font></b></td>
			        	<td><input type="image" height="20" width="20" src="images/go.png" /></font></b></td>
			        	</tr>
			        	<%
		        	}else if(voteTime.after(today)){
		        		%>
			        	<tr>
			        	<td><b><font COLOR="#FFE4B5"><center><%=rset.getInt(1)%></font></center></b></td>
			        	<td><b><font COLOR="#FFE4B5"><center><%=rset.getString(2)%> - <%=rset.getDate(3)%></font></center></b></td>
			        	<td><b><font COLOR="#FFE4B5"><center><%=rset.getString("time")%></font></center></b></td>
			        	<td><b><font COLOR="#FFE4B5"><center><%=rset.getString(7)%> vs <%=rset.getString(8)%></font></center></b></td>
			        	<td><b><font COLOR="#FFE4B5"><center><%=rset.getString(11)%></font></center></b></td>
			        	<td><b><font COLOR="#FFE4B5"><center><%=rset.getString(9)%></font></center></b></td>
			        	<td><b><font COLOR="#FFE4B5"><center><%=rset.getString(10)%></font></center></b></td>
			        	<td><b><font COLOR="#FFE4B5"><center><input type="radio" name="matchId" value="<%=parameter%>"></font></b></td>
			        	<td><input type="image" height="20" width="20" src="images/blackPlay.png"/></font></b></td>
			        	</tr>
			        	<%
		        	}
		        }
		        stmt.close();
		        conn.close();
			}
	  		catch ( Exception e1){
				e1.printStackTrace();
			} 
			finally{
			}
      %>

</tbody>
</table>
</form>
        </div>
       </div>
      </div>
   </body>
 </html>
<%
   if ( session.getAttribute("resposeText") != null && !("").equals(session.getAttribute("resposeText")))
   { 
		session.setAttribute("resposeText", null);
   }
}else {
	%>
		<jsp:forward   page="login.jsp"/>
	<%
}
%>